package net.ithe.service.impl;

import net.ithe.mapper.DeptMapper;
import net.ithe.pojo.Dept;
import net.ithe.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {

    @Autowired
    private DeptMapper deptMapper;
    @Override
    public List<Dept> findAll() {
        return deptMapper.findAll();
    }

    @Override
    public void deleteById(Integer id) {
        deptMapper.deleteById(id);
    }

    @Override
    public void add(Dept dept) {
        //补充创建时间和修改时间
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        //调用Mapper的方法
        deptMapper.insert(dept);
    }

    @Override
    public Dept getById(Integer id) {
       return deptMapper.getById(id);
    }

    /**
     * 修改
     * @param dept
     */
    @Override
    public void update(Dept dept) {
        //补全数据
        dept.setUpdateTime(LocalDateTime.now());
        //调用Mapper
        deptMapper.update(dept);
    }
}
